function e(e) {
    return (e = e.toString())[1] ? e : "0" + e;
}

function t(e) {
    return e.replace(/[\u0391-\uFFE5]/g, "aa").length;
}

module.exports = {
    formatTime: function(t) {
        var n = t.getFullYear(), r = t.getMonth() + 1, a = t.getDate(), i = t.getHours(), o = t.getMinutes(), u = t.getSeconds();
        return [ n, r, a ].map(e).join("/") + " " + [ i, o, u ].map(e).join(":");
    },
    getDateDiff: function(e) {
        var t, n, r, a, i, o = Date.parse(e.replace(/-/gi, "/")) / 1e3, u = parseInt(new Date().getTime() / 1e3), s = new Date(1e3 * o), g = s.getFullYear(), c = s.getMonth() + 1, l = s.getDate(), f = s.getHours(), p = s.getMinutes(), m = s.getSeconds();
        return c < 10 && (c = "0" + c), l < 10 && (l = "0" + l), f < 10 && (f = "0" + f), 
        p < 10 && (p = "0" + p), m < 10 && (m = "0" + m), i = u - o, a = parseInt(i / 86400), 
        r = parseInt(i / 3600), n = parseInt(i / 60), t = parseInt(i), a > 0 && a < 3 ? a + "天前" : a <= 0 && r > 0 ? r + "小时前" : r <= 0 && n > 0 ? n + "分钟前" : t < 60 ? t <= 0 ? "刚刚发表" : t + "秒前" : a >= 3 && a < 30 ? c + "月" + l + "日" : a >= 30 ? g + "年" + c + "月" + l + "日" : void 0;
    },
    cutstr: function(e, t, n) {
        for (var r = 0, a = 0, i = new String(), a = e.length, o = 0; o < a; o++) {
            var u = e.charAt(o);
            if (r++, escape(u).length > 4 && r++, i = i.concat(u), r >= t) return 0 == n && (i = i.concat("...")), 
            i;
        }
        if (r < t) return e;
    },
    removeHTML: function(e) {
        var t = e.replace(/<\/?.+?>/g, "");
        return (t = t.replace(/[\r\n]/g, "")).replace(/ /g, "");
    },
    formatDateTime: function(e) {
        return e.replace("T", " ");
    },
    compare: function(e) {
        return function(t, n) {
            var r = t[e], a = n[e];
            return r > a ? -1 : r < a ? 1 : 0;
        };
    },
    checkImgType: function(e) {
        return !!/\.(gif|jpg|jpeg|png|GIF|JPG|PNG)$/.test(e);
    },
    isEmptyObject: function(e) {
        var t;
        for (t in e) return !1;
        return !0;
    },
    CheckImgExists: function(e) {
        var t = new Image();
        return t.src = e, t.fileSize > 0 || t.width > 0 && t.height > 0;
    },
    GetUrlFileName: function(e, t) {
        var n = e.substring(e.lastIndexOf("/") + 1);
        return n = n == t || "" == n ? "index" : n.substring(0, n.lastIndexOf("."));
    },
    json2Form: function(e) {
        var t = [];
        for (var n in e) t.push(encodeURIComponent(n) + "=" + encodeURIComponent(e[n]));
        return t.join("&");
    },
    getymd: function(e, t) {
        e = e.replace("T", " ");
        var n = new Date(Date.parse(e.replace(/-/g, "/"))), r = n.getMonth() + 1, a = n.getDate(), i = n.getFullYear();
        return "d" == t ? a : "md" == t ? r + "-" + a : "ymd" == t ? i + "-" + r + "-" + a : void 0;
    },
    getDateOut: function(e) {
        var t = Date.parse(e.replace(/-/gi, "/")) / 1e3, n = !1, r = parseInt(new Date().getTime() / 1e3) - t;
        return parseInt(r / 86400) > 7 && (n = !0), n;
    },
    drawTitleExcerpt: function(e, n, r) {
        e.setFillStyle("#000000"), e.setTextAlign("left"), t(n) <= 14 ? (e.setFontSize(40), 
        e.fillText(n, 40, 460)) : (e.setFontSize(30), e.fillText(n.substring(0, 19), 40, 460), 
        e.fillText(n.substring(19, 36), 40, 510)), e.setFontSize(24), e.setTextAlign("left"), 
        e.setGlobalAlpha(.7);
        for (var a = 0; a <= 50; a += 20) t(r) > 50 && 40 == a ? e.fillText(r.substring(a, a + 20) + "...", 40, 570 + 2 * a) : e.fillText(r.substring(a, a + 20), 40, 570 + 2 * a);
        e.stroke(), e.save();
    },
    getStrLength: t
};